<template>
	<view>
		<view class="header">
			<view class="loginHeader">
				<image src="https://z3.ax1x.com/2021/04/17/c4kvIU.png" mode="" style="width: 168rpx; height: 168rpx;"></image>
			</view>
		</view>
		<view class="inputBox">
			<view class="userBox">
				<view class="userInput">
					<image src="https://z3.ax1x.com/2021/04/17/c4Zrwt.png" mode="" style="width: 30rpx; height: 36rpx; margin-right: 20rpx;"></image>
					<input type="text" value="" placeholder="请输入用户名" v-model="userData.username"/>
				</view>
				<view class="userInput">
					<image src="https://z3.ax1x.com/2021/04/17/c4mrPf.png" mode="" style="width: 30rpx; height: 36rpx; margin-right: 20rpx;"></image>
					<input type="text" value="" placeholder="请输入密码" v-model="userData.password"/>
					<image class="lookPassword" src="https://z3.ax1x.com/2021/04/17/c4rd1O.png" mode="" style="width: 42rpx; height: 28rpx;"></image>
				</view>
			</view>
			<view class="tmpBox">
				<view class="registerBox" @tap="toRegister">
					<text>立即注册</text>
				</view>
				<view class="forgetBox">
					<text>忘记密码</text>
				</view>
			</view>
			<view class="loginBtn" @tap="login">
				<text>登陆</text>
			</view>
		</view>
		<view class="wayBox">
			<view class="lineLeft"></view>
			<view class="wayText">
				<text>其他登陆方式</text>
			</view>
			<view class="lineRight"></view>
		</view>
		<view class="wayBtn">
			<image src="https://z3.ax1x.com/2021/04/17/c4Gf6x.png" mode="" style="width: 76rpx;height: 76rpx;"></image>
			<image src="https://z3.ax1x.com/2021/04/17/c4GhX6.png" mode="" style="width: 76rpx;height: 76rpx;"></image>
			<image src="https://z3.ax1x.com/2021/04/17/c4GRpR.png" mode="" style="width: 76rpx;height: 76rpx;"></image>
			<image src="https://z3.ax1x.com/2021/04/17/c4GW11.png" mode="" style="width: 76rpx;height: 76rpx;"></image>
		</view>
	</view>
</template>

<script>
	import apis from '../../api/apis.js'
	import {createNamespacedHelpers} from 'vuex'
	const {mapMutations} = createNamespacedHelpers('UserInfor')
	export default {
		data() {
			return {
				userData:{
					username: '17383848096',
					password: 'abc123456',
				}
			}
		},
		methods: {
			...mapMutations(['getUserData','preservation']),
			toRegister(){
				uni.redirectTo({
					url:'../register/register'
				})
			},
			 async login(){
				let data =await apis.login.login(this.userData);
				if(data.code==200){
					uni.showToast({
						title: '登录成功！',
						duration: 2000
					});
					///保存token至本地
					uni.setStorage({
						key:'token',
						data:data.data.token
					})
					///用户数据保存至状态机便于个人中心使用
					this.getUserData(data.data)
					///保存密码
					this.preservation(this.userData.password)
					//跳转页面
					uni.navigateBack({
					    url: '/pages/home/home',
						delta:1
					});
				}else if(data.code==602){
					uni.showModal({
						title: '提示',
						content: '账号无效请注册!',
						showCancel: false,
						success: function(res) {
							if (res.confirm) {
								uni.redirectTo({
									url: '../register/register',
								});
							}
						}
					});
				}else if(data.code==601){
					uni.showModal({
						title: '提示',
						content: '账号密码错误!',
						showCancel: false,
					});
				}
				console.log(data)
			}
		}
	}
</script>

<style>
	.header{
		height: 400rpx;
		background: url('https://z3.ax1x.com/2021/04/17/c4ijO0.png') no-repeat;
		background-size:cover;
		position: relative;
	}
	.loginHeader{
		width:168rpx ;
		position: absolute;
		top: 328rpx ;
		right: 0;
		left: 0;
		bottom: 0;
		margin: auto;
	}
	.inputBox{
		width: 700rpx;
		background: #FFFFFF;
		box-shadow: 0px 0px 24rpx rgba(0, 0, 0, 0.1);
		border-radius: 12rpx;
		margin:120rpx auto  46rpx auto;
		padding: 42rpx 30rpx;
		box-sizing: border-box;
	}
	.userBox{
		margin-top: 76rpx;
	}
	.userInput{
		margin-top: 30rpx;
		height: 60rpx;
		display: flex;
		border-bottom: 2rpx solid rgba(0, 0, 0, 0.05);
		position: relative;
	}
	.lookPassword{
		position: absolute;
		right: 20rpx;
	}
	.tmpBox{
		display: flex;
		margin-top: 30rpx;
	}
	.registerBox{
		width: 350rpx;
		color: #3476F1;
		font-size: 24rpx;
	}
	.forgetBox{
		width: 350rpx;
		text-align: right;
		font-size: 24rpx;
		color: #999999;
	}
	.loginBtn{
		width: 642rpx;
		height: 88rpx;
		border-radius: 52rpx;
		background:linear-gradient(180deg, #729EFA 0%, #3476FE 100%);
		margin-top: 30rpx;
		color: #FFFFFF;
		text-align: center;
		line-height: 88rpx;
		margin-bottom: 86rpx;
	}
	.wayBox{
		display: flex;
		align-items: center;
		justify-content: center;
	}
	.lineLeft{
		width: 79px;
		height: 1px;
		background: linear-gradient(270deg, #A6A6A6 0%, #FFFFFF 100%);
		opacity: 1;
	}
	.lineRight{
		width: 79px;
		height: 1px;
		background: linear-gradient(270deg,#FFFFFF 0%, #A6A6A6  100%);
		opacity: 1;
	}
	.wayText{
		font-size: 28rpx;
		font-family: PingFang SC;
		font-weight: 400;
		line-height: 40rpx;
		color: #A6A6A6;
		margin: 0 20rpx 0 20rpx;
	}
	.wayBtn{
		width: 410rpx;
		margin: 20rpx auto;
		display: flex;
		justify-content: center;
	}
	.wayBtn>image{
		margin: 0 15rpx;
	}
</style>
